from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import reverse,redirect
from app01 import models
class Middleware(MiddlewareMixin):
    def process_request(self,request):
        if request.path_info in [reverse('login'),reverse('register')]:
            return
        if request.path_info.startswith('/admin/'):
            return
        is_login = request.session.get('login')
        if not is_login:
            return  redirect(reverse('login'))
        request.user_obj = models.UserProfile.objects.get(name=request.session.get('login'))
